package com.gf.framework.rediscachedemo.controller;

import com.gf.framework.redis.annotation.CacheExpire;
import io.swagger.annotations.Api;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.TimeUnit;

@RestController
@Api(tags = "redis cache测试接口")
@RequestMapping("rediscache/test")
public class CacheTestController {
    @Cacheable("hello")
    @GetMapping("hello")
    public String hello() {
        return "hello";
    }

    /**
     * 超时时间设置
     * @return
     */
    @Cacheable("expiretest1")
    // 固定超时10秒
    @CacheExpire(expire = 10, timeUnit = TimeUnit.SECONDS)
    @GetMapping("expiretest1")
    public String expiretest1() {
        return "expiretest1";
    }

    @Cacheable("expiretest2")
    // 随机超时5-15秒
    @CacheExpire(expire = 10, timeUnit = TimeUnit.SECONDS, range = 5)
    @GetMapping("expiretest2")
    public String expiretest2() {
        return "expiretest2";
    }

    @Cacheable("expireConfigTest1")
    @GetMapping("expireConfigTest")
    public String expireConfigTest() {
        return "expireConfigTest";
    }

    @Cacheable(value = "expireConfigTest2")
    @GetMapping("expireConfigTest2")
    public String expireConfigTest2() {
        return "expireConfigTest2";
    }
}
